using Autofac;

using Cookbook.Services.Core.Persistency;

using FluentNHibernate.Cfg.Db;

using NHibernate.ByteCode.Castle;

namespace Cooking.Services.Specs.Persistency
{
    public class SqlLiteUnitOfWorkModule : CookbookUnitOfWorkModule
    {
        public SqlLiteUnitOfWorkModule() : base("")
        {
        }

        protected override void RegisterFactory(ContainerBuilder builder)
        {
            builder.RegisterType<SqlLiteUnitOfWorkFactory>();
            builder
                .Register(c => c.Resolve<SqlLiteUnitOfWorkFactory>().Create())
                .ExternallyOwned();
        }

        protected override IPersistenceConfigurer DatabaseConfiguration
        {
            get
            {
                return SQLiteConfiguration
                    .Standard
                    .InMemory()
                    .ProxyFactoryFactory(typeof(ProxyFactoryFactory).AssemblyQualifiedName);
            }
        }
    }
}